package com.gwz.cardserver.consts;

import com.gwz.cardserver.dto.fight.CardDto;

import java.util.List;

public enum CardWeightEnums {
    THREE(3),
    FOUR(4),
    FIVE(5),
    SIX(6),
    SEVEN(7),
    EIGHT(8),
    NINE(9),
    TEN(10),

    JACK(11),
    QUEEN(12),
    KING(13),

    ONE(14),
    TWO(15),

    SJOKER(16),
    LJOKER(17),

    ;
    private int code;

    CardWeightEnums(int code) {
        this.code = code;
    }


    public static CardWeightEnums getByCode(int code) {
        for (CardWeightEnums value : values()) {
            if (value.code == code) {
                return value;
            }
        }
        return null;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    /**
     * 获取出牌权重
     *
     * @param cardDtos 选择的卡牌
     * @param cardType 出牌类型
     * @return
     */
    public static int getWeight(List<CardDto> cardDtos, int cardType) {
        int totalWeight = 0;
        if (cardType == CardTypeEnum.THREE_ONE.getCode() || cardType == CardTypeEnum.THREE_TWO.getCode()) {
            // 如果是 三代一 三代二
            for (int i = 0; i < cardDtos.size(); i++) {
                if (cardDtos.get(i).getWeight() == cardDtos.get(i + 1).getWeight() && cardDtos.get(i).getWeight() == cardDtos.get(i + 2).getWeight()) {
                    totalWeight += (cardDtos.get(i).getWeight() * 3);
                }
            }
        } else {
            for (int i = 0; i < cardDtos.size(); i++) {
                totalWeight += cardDtos.get(i).getWeight();
            }
        }
        return totalWeight;
    }
}
